package PayrollTest

import (
	"SPC/Database"
	"SPC/Model"
	"SPC/ModelImplementation"
	"SPC/TransactionImplementation"
	"fmt"
	"time"
)

type PayrollTest struct {
}

//测试函数：增加薪水支付类型员工
func (p *PayrollTest) TestAddSalaryedEmployee() {
	var empId = 1
	//创建一个增加薪水支付类型的员工的实例
	t := TransactionImplementation.NewAddSalariedEmployee(empId, "Bob", "Home", 1000.00)
	t.Execute()

	//从数据库中获取刚刚插入的员工的信息
	var e Model.Employee = Database.GetPayrollDatabase().GetEmployee(empId)
	fmt.Println("刚刚插入的员工的姓名为：" + e.GetName())
}

//测试函数：删除员工
func (p *PayrollTest) TestDeleteEmployee() {
	fmt.Println("开始删除员工")
	empId := 3
	t := TransactionImplementation.NewAddCommissionedEmployee(empId, "Lance", "Home", 2500, 3.2)
	t.Execute()

	e := Database.GetPayrollDatabase().GetEmployee(empId)
	fmt.Println(e)

	//删除
	dt := TransactionImplementation.NewDeleteEmployeeTransaction(empId)
	dt.Execute()

	//检验是否删除
	e = Database.GetPayrollDatabase().GetEmployee(empId)
	fmt.Println(e)
}

//测试函数：时间卡，销售凭条以及服务费用
func (p *PayrollTest) TestTimeCardTransaction() {
	fmt.Println("开始添加时间卡，销售凭条以及服务费用")
	empId := 2
	t := TransactionImplementation.NewAddHourlyEmployee(empId, "Bill", "Home", 15.25)
	t.Execute()
	fmt.Println("插入成功")

	tct := TransactionImplementation.NewTimeCardTransaction(time.Date(2001, 10, 30, 0, 0, 0, 0, time.Local), 8.0, empId)
	tct.Execute()
	fmt.Println("插入时间卡成功")
}

//测试函数：添加协会成员id
func (p *PayrollTest) TestAddServiceCharge() {
	fmt.Println("开始添加协会成员id")
	empId := 2
	t := TransactionImplementation.NewAddHourlyEmployee(empId, "Bill", "Home", 15.25)
	t.Execute()
	fmt.Println("插入成功")

	e := Database.GetPayrollDatabase().GetEmployee(empId)
	fmt.Println(e)

	memberId := 86
	af := ModelImplementation.NewUnionAffliliation(memberId, 12.5)
	e.SetAffiliation(af)

	Database.GetPayrollDatabase().AddUnionMember(memberId, e)
	sct := TransactionImplementation.NewServiceChargeTransaction(memberId, time.Now(), 12.95)
	sct.Execute()

	fmt.Println("添加成功")
}

//测试函数：更改成员名称
func (p *PayrollTest) TestChangeNameTransaction() {
	fmt.Println("更改成员名称开始")
	empId := 2
	t := TransactionImplementation.NewAddHourlyEmployee(empId, "Bill", "Home", 15.25)
	t.Execute()

	cnt := TransactionImplementation.NewChangeNameTransaction(empId, "Bob")
	cnt.Execute()

	e := Database.GetPayrollDatabase().GetEmployee(empId)
	fmt.Println(e)
	fmt.Println("修改完毕")
}

//测试函数：更改成员支付方式
func (p *PayrollTest) TestChangeHourlyTransaction() {
	fmt.Println("更改成员支付方式")
	empId := 3
	t := TransactionImplementation.NewAddHourlyEmployee(empId, "Bill", "Home", 15.25)
	t.Execute()

	cnt := TransactionImplementation.NewChangeNameTransaction(empId, "Bob")
	cnt.Execute()

	e := Database.GetPayrollDatabase().GetEmployee(empId)
	fmt.Println(e)
	fmt.Println("更改完毕")
}